//
//  ViewController.swift
//  SwiftUITemp
//
//  Created by MyMac on 15/10/13.
//  Copyright (c) 2015年 tongfang. All rights reserved.
//

import UIKit
import Foundation

typealias ClickBtn = (_ name:String)->String
class ViewController: UIViewController ,transmitValue{
//override表明是继承过来的,复写基类的方法必须这样
    var label:UILabel?
    
    
    //协议定义了实现某些事情需要的一个标准／模式,transmitValue协议需要一个方法和一个属性，所以ViewController必须要有和transmitValue一样的方法和属性(proprtoy)
    var proprtoy:Int = 0
    var c:ClickBtn?
   static var classP:Int=8
    
    
    var count:Int = 0

    var transmitLabel :UILabel?
     override func viewDidLoad() {
        super.viewDidLoad()
        var closure:ClickBtn  = { name in
        
        return "haha"
        
        }
        var tempClosure={(name:String , count:Int )in
            
            
            return name
        
        
        }
        transmitLabel=UILabel(frame: CGRect(x: 0, y: 400, width: 320, height: 44))
        transmitLabel?.backgroundColor=UIColor.yellow
        self.view.addSubview(transmitLabel!)
        
        print(closure("haha"))
        print(tempClosure("aaaaa",10))
        
        self.view!.backgroundColor=UIColor(red: 0.9, green: 0.6, blue: 0.4, alpha: 1)
       
        let rect=CGRect(x: 0, y: 100, width: 320, height: 44)
        let myLabel=UILabel(frame: rect)
        self.label=myLabel
        myLabel.backgroundColor=UIColor.white
        myLabel.text="haha"
        myLabel.textAlignment=NSTextAlignment.center
        self.view!.addSubview(myLabel)
        
        
        let btn=UIButton(frame: CGRect(x: 0, y: 200, width: 320, height: 44))
        btn.setTitle("点击我", for: UIControlState())
        btn.backgroundColor=UIColor.green
        //Selector是一个结构体，初始化方法有多种
       let sele = #selector(ViewController.btnClick(_:))
        btn.addTarget(self, action: sele, for:UIControlEvents.touchUpInside)
        self.view.addSubview(btn)
        
    }
    
        func btnClick (_ btn:UIButton) {
        count += 1
    let content : String = "点击了\(count)次";
    print(content)
           let vc=FristVC()
           vc.delegate = self
           
            vc.closure = {(str)-> String in
                print(str)
               
                return str
            
            
            
            }
            
           self.proprtoy = 10//协议中的属性
            
            self.navigationController?.pushViewController(vc, animated: true)
        label!.text = content
    
    }
    
   
    func valueChange(_ value: String) {
        self.transmitLabel?.text=value
    }
    
//    static func classFunc() {
//        println("代理可选方法")
//    }
}

